library(ggplot2)

dem <- read.csv("main_categorized.csv",header=T, stringsAsFactors=FALSE)
dem$pe <- dem$c1
dem$se <- dem$c2
dem$lb <- dem$pe- 1.96*dem$se
dem$ub <- dem$pe+ 1.96*dem$se

#Category Factors
dem$col <- factor (dem$c3, levels=seq(1,5), 
                   labels= c("Systemic Injustice", "Class-Based Injustice","Class-Based Education Inequality", "Racial Injustice", "Racial Prejudice"))
dem$group <- factor(dem$c4,levels=seq(26,1),
                    labels=c("Level of Respect of U.S. Political Insitutions",
                             "Sense That Citizen's Basic Right's Are Protected by the U.S. Political System",
                             "System Support Index",
                             "Incomes Should be Made More Equal (As Opposed to Unequal to Incentivize Individual Effort",
                             "Gov't (as Opposed to Individuals) Should Take More Responsibility to Ensure That Everyone is Provided For",
                             "Hard Work Doesn't Generally Bring Success- It's More a Matter of Luck and Connections",
                             "People Are Poor Because of Unfair Society (as Opposed to Laziness and Lack of Willpower)",
                             "Class-Based Injustice Index",
                             "Contributor to Education Inequality: Poor Families Do Not Value Education as Much as Richer Families",
                             "Contributor to Education Inequality: Systemic Injustices Perpetuate Inequity Throughout Society",
                             "Agreement That Low Income Students Have Same Educational Opportunities as High Income Students",
                             "Agreement That Blacks Have Gotten Less Than They Deserve",
                             "Agreement That Blacks Should Overcome Prejudice Without Special Favors",
                             "Agreement That It's Really Just a Matter of Blacks Working Harder to be Just as Well Off as Whites",
                             "Agreement That Slavery and Discrimination Has Made it Difficult for Blacks to Work Their Way Up",
                             "Extent to Which Racial Discrimination Limits Particular Racial Groups",
                             "Racial Resentment Index",
                             "Satisfaction with Treatment of Asians",
                             "Satisfaction with Treatment of Hispanics",
                             "Satisfaction with Treatment of Blacks",
                             "Satisfaction with Treatment of Muslims",
                             "Satisfaction with Treatment of Immigrants",
                             "Discrimination Index",
                             "Skin-Tone Implicit Association Test",
                             "Feel Close to Blacks",
                             "Feel Close to Hispanics"
                    )[26:1])

f1 = ggplot(data = dem, aes(x = group, y = pe, width=0.5,ymin = lb, ymax = ub, color=col))

f1 = f1 + geom_point(aes(shape = col), size = 3)
f1 = f1 + geom_pointrange(size=0.25, position = position_dodge(width=.5))
f1 = f1 + scale_shape_manual(values=c(1,2,3,4,5))  
f1 = f1 + scale_fill_manual(values=c("black","black"))

#Error Bars
f1 = f1+ geom_errorbar(aes(ymin=dem$pe- dem$se, ymax=dem$pe+ dem$se), width=.1)

f1 = f1 + coord_flip()
f1 = f1 + geom_hline(yintercept=0, linetype="longdash", size=0.5)
f1 = f1 + labs( y= "Treatment Effect", x = "Dependent Variable", shape = "Category", color = "Category")

#Limits - Set this to whatever you'd like limits to be.
#f1 = f1 + scale_y_continuous(limits = c(-0.2,0.2))

#Theme
f1 =f1+ theme(plot.background= element_rect(fill="grey100"),
              panel.background= element_rect(fill="grey100", color= "grey75"),
              panel.grid.major = element_line(color= "grey75"),
              panel.grid.minor = element_line(color= "grey80"),
              panel.grid.major.y = element_blank(),
              panel.grid.minor.y = element_blank(),
              panel.spacing.x = unit(12,"point"),
              legend.position = c(-0.5,0.1),
              legend.background = element_rect(fill="grey100")
)



print(f1)